***************pull PULHES scores*****************


use pid_pde date_snapshot e1phcp  e1psyc using "$data_in/Personnel", clear
rename e1* *
replace date_snapshot = dofc(date_snapshot)
format date_snapshot %d
destring psyc, replace
destring phcp, replace
keep if (psyc > 1 & psyc < .) | (phcp > 1 & phcp < .)
bys pid_pde (date_snapshot): gen n = _n


summ n 
local max_r `r(max)'
reshape wide date_snapshot phcp psyc, i(pid_pde) j(n)
merge 1:m pid_pde using "$data_out/provider_propensity", keep(2 3) nogen
keep if officer == 0 & service == "A"


gen physical = 1
gen psych = 1
forval i = 1/`max_r' {
qui replace physical = phcp`i' if inrange(date_snapshot`i', encdate, encdate + 365) & phcp`i' <. & phcp`i' > physical 
qui replace psych = psyc`i' if inrange(date_snapshot`i', encdate, encdate + 365) & psyc`i' <. & psyc`i' > psych 
}




foreach var of varlist physical psych {
summ `var'
gen `var'_Z = (physical - `r(mean)')/`r(sd)'
}

save "$data_out/PULHES"

